﻿/**
 * author:  Martin Hrabos
 * year:    2016
 * email:   hrabosmartin@gmail.com
 * 
 * FIT Brno University of Technology / ASCR Brno
 */

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CorrCL
{
    /*
     * Class for storing objects related to results
     */
    class ResultMatrix
    {
        public BlockingCollection<ResultPoint> results;
        public List<String> labels;
        public readonly int LONGEST_LABEL_LENGTH;
        public float frequency;
        public long windowSize;
        public long windowOffset;
        public long size;
        public string sourceFile;


        public ResultMatrix(List<String> labelList, float freq)
        {
            results = new BlockingCollection<ResultPoint>();
            labels = labelList;
            frequency = freq;

            string longest = labels.OrderByDescending(s => s.Length).First();
            LONGEST_LABEL_LENGTH = TextRenderer.MeasureText(longest, SystemFonts.DefaultFont).Width;
        }

        // Add new result object
        // public void Add(float[] values, int row, int col)
        public void Add(List<float[]> blocks, int row, int col)
        {
            ResultPoint rp = new ResultPoint(blocks, row, col, LONGEST_LABEL_LENGTH, labels[row+1], labels[col]);
            rp.originSize = this.size;
            rp.sourceFile = this.sourceFile;
            results.Add(rp);

        }

        // Get ResultPoint according to clicked position
        public ResultPoint getResultPointbyClick(int x, int y)
        {

            foreach(ResultPoint rp in results)
            {
                if (x >= rp.getRectangle().X && x <= rp.getRectangle().X + ResultPoint.RECT_WIDTH &&
                    y >= rp.getRectangle().Y && y <= rp.getRectangle().Y + ResultPoint.RECT_HEIGHT)
                {
                    //Debug.WriteLine("HIT");
                    //Debug.WriteLine(rp.getMaxValue());
                    return rp;
                }
            }

            // If not found, return null
            return null;
        }
    }
}
